package com.sjc.lesson04.demo05;

import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.functions.AssignerWithPeriodicWatermarks;
import org.apache.flink.streaming.api.watermark.Watermark;

import javax.annotation.Nullable;

public class EventTimeExtractor implements AssignerWithPeriodicWatermarks<Tuple2<String,Long>> {
    FastDateFormat dateFormat = FastDateFormat.getInstance("HH:mm:ss");

    @Nullable
    @Override
    public Watermark getCurrentWatermark() {
        return new Watermark(System.currentTimeMillis());
    }

    // 拿到每一个事件的 Event Time
    @Override
    public long extractTimestamp(Tuple2<String, Long> element, long previousElementTimestamp) {
        return element.f1;
    }
}
